const gulp = require('gulp');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const gap = require('gulp-append-prepend');

const config = {
	src: [
		'./src/init.es6',
		'./src/system.es6',
		'./src/request.es6',
		'./src/view.es6',
		'./src/media.es6',
		'./src/storage.es6',
		'./src/cookie.es6',
		'./src/clipboard.es6',
		'./src/router.es6',
	]
};

function build() {
	console.log('开始编译文件...');
	return gulp.src(config.src)
		.pipe(babel({
			presets: [
				[
					"@babel/preset-env",
					{
						"loose": true,
						"modules": false,
						"shippedProposals": true
					}
				]
			]
		}))
		.pipe(concat('index.js'))
		.pipe(gap.appendText('export default $;'))
		.pipe(gulp.dest('./dist'));
}

gulp.task('default', function() {
	const watcher = gulp.watch(config.src, gulp.series(build));
	return build();
});

